try:
    print('try: ')
    100/0
    print('never reach here')
except ZeroDivisionError:
    print('except ZeroDivisionError: ')

def generateError():
    import random
    number=random.randint(0,1)
    if number == 0:
        100/0
    else:
        file=open('none-exist-file')
try:
    print('try: ')
    generateError()
    print('never reach here')
except ZeroDivisionError:
    print('except ZeroDivisionError: ')
except IOError:
    print('except IOError: ')

try:
    parts=['www','imooc','com']
    print(parts[3])
except Exception as e:
    print('except: %s'%e)

try:
    f=open('test.txt')
    line=f.readline()
    print(line)
    f.close()
except IOError:
    print('except IOError:')
else:
    print(line)
    f.close()

try:
    print('try: ')
    100/0
finally:
    print('finally: ')

try:
    f=open('test.txt')
    line=f.readline()
    print(line)
except IOError:
    print('except IOError')
finally:
    if 'f' in vars():
        f.close()

try:
    print('try: ')
    raise
    print('never reach here')
except:
    print('except: ')

try:
    print('try: ')
    raise ValueError
    print('never reach here')
except ValueError:
    print('except ValueError: ')

try:
    text=input('Please enter a digit: ')
    if not text.isdigit():
        info='"%s" is not digit.'%text
        raise ValueError(info)
except ValueError as e:
    print('except ValueError: %s'%e)
